<?php
/**
 * @package YARBB
 * @copyright Авторские права (C) 2009 www.yar-it.com. Все права защищены.
 * @license Лицензия http://www.gnu.org/licenses/gpl-2.0.htm GNU/GPL, или help/license.php
 * YARBB! - свободное программное обеспечение распространяемое по условиям лицензии GNU/GPL
 * Для получения информации о используемых расширениях и замечаний об авторском праве, смотрите файл copyright.php.
 */

// no direct access
defined( '_VALID_MOS' ) or die( 'Прямой доступ запрещен.' );

// Добавить форум по умолчанию
if (isset($_POST['add_forum'])) {
	$add_to_cat = intval($_POST['add_to_cat']);
	if ($add_to_cat < 1)
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_404);
	$sql = ('INSERT INTO #__forum_forums (cat_id) VALUES('.$add_to_cat.')');
	$database->setQuery($sql);
	$database->Query($sql);
	// Regenerate the quickjump cache
	require_once $yarbb_admin_path.'/include/cache.php';
	generate_quickjump_cache();
	mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _E_ITEM_SAVED);
}
// Delete a forum
else if (isset($_GET['del_forum'])) {

	$forum_id = intval($_GET['del_forum']);
	if ($forum_id < 1)
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_404);
	if (isset($_POST['del_forum_comply']))	// Delete a forum with all posts
	{
		//@set_time_limit(0);
		// Prune all posts and topics
		//prune($forum_id, 1, -1);
		// Locate any "orphaned redirect topics" and delete them
		$database->setQuery('SELECT t1.id FROM #__forum_topics AS t1
					LEFT JOIN #__forum_topics AS t2 ON t1.moved_to=t2.id 
					WHERE t2.id IS NULL 
					AND t1.moved_to IS NOT NULL');
		$num_orphans = $database->getNumRows();
		if ($num_orphans) {
			//s
			$orphans=$database->loadResultArray();
			/*	for ($i = 0; $i < $num_orphans; ++$i)
				$orphans[] = $db->result($result, $i);*/

			$sql = ('DELETE FROM #__forum_topics WHERE id IN('.implode(',', $orphans).')');
			$database->setQuery($sql);
			$database->Query($sql);
		}
		// Delete the forum and any forum specific group permissions
		$sql = ('DELETE FROM #__forum_forums WHERE id='.$forum_id);
		$database->setQuery($sql);
		$database->Query($sql);
		$sql = ('DELETE FROM #__forum_forum_perms WHERE forum_id='.$forum_id);
		$database->setQuery($sql);
		$database->Query($sql);
		// Regenerate the quickjump cache
		require_once $yarbb_admin_path.'/include/cache.php';
		generate_quickjump_cache();
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _DELETE_SUCCESS);
	}
	else	// Если пользователь не подтвердил удаление
	{
		$sql = ('SELECT forum_name FROM #__forum_forums WHERE id='.$forum_id);
		$database->setQuery($sql);
		$forum_name = yarbb_htmlspecialchars($database->loadResult());

		?>

<table class="adminheading">
	<tr>
		<th class="menus"> <span><?php echo _Y_FORUMDEL; ?></span> </th>
	</tr>
</table>
<form method="post" action="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;del_forum='.$forum_id; ?>">
	<table class="adminform">
		<tr>
			<th colspan="4"> <?php echo _Y_CATDELAVT; ?></th>
		</tr>
		<tr>
			<td><p><?php echo _Y_FORUMDELUVER; ?> [<?php echo $forum_name ?>] ?</p>
				<p><?php echo _Y_FORUMDELWAR; ?></p>
				<p>
					<input type="submit" name="del_forum_comply" value="<?php echo _E_REMOVE; ?>" />
					<input onclick="javascript:history.go(-1)" name="" type="button" value="<?php echo _CMN_CANCEL; ?>" />
				</p></td>
		</tr>
	</table>
</form>
		<?php

	}
}
// Update forum positions
else if (isset($_POST['update_positions'])) {

	while (list($forum_id, $disp_position) = @each($_POST['position'])) {
		if (!preg_match('#^\d+$#', $disp_position))
			mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_CATPOSITERR);
		$sql = ('UPDATE #__forum_forums
				SET disp_position='.$disp_position.' 
				WHERE id='.intval($forum_id));
		$database->setQuery($sql);
		$database->Query($sql);
	}
	// Regenerate the quickjump cache
	require_once $yarbb_admin_path.'/include/cache.php';
	generate_quickjump_cache();
	mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _POSITIONS_SAVED);
}


else if (isset($_GET['edit_forum'])) {
	$forum_id = intval($_GET['edit_forum']);
	if ($forum_id < 1)
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_404);
	// Update group permissions for $forum_id
	if (isset($_POST['save'])) {

		// Start with the forum details
		$forum_name = trim($_POST['forum_name']);
		$forum_desc = yarbb_linebreaks(trim($_POST['forum_desc']));
		$forum_key = yarbb_linebreaks(trim($_POST['forum_key']));
		$forum_mdesc = yarbb_linebreaks(trim($_POST['forum_mdesc']));
		$cat_id = intval($_POST['cat_id']);
		$sort_by = intval($_POST['sort_by']);
		$redirect_url = isset($_POST['redirect_url']) ? trim($_POST['redirect_url']) : null;
		$parent_forum_id = intval($_POST['parent_forum']);
		$published = intval($_POST['published']);

		if ($forum_name == '')
			mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_FONONEME);
		if ($cat_id < 1)
			mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_404);
		$forum_desc = ($forum_desc != '') ? '\''.$database->getEscaped($forum_desc).'\'' : 'NULL';
		$forum_key = ($forum_key != '') ? '\''.$database->getEscaped($forum_key).'\'' : 'NULL';
		$forum_mdesc = ($forum_mdesc != '') ? '\''.$database->getEscaped($forum_mdesc).'\'' : 'NULL';

		$redirect_url = ($redirect_url != '') ? '\''.$database->getEscaped($redirect_url).'\'' : 'NULL';
		$sql = ('UPDATE #__forum_forums
					SET forum_name=\''.$database->getEscaped($forum_name).'\', forum_desc='.$forum_desc.', 
					forum_key='.$forum_key.', forum_mdesc='.$forum_mdesc.', 
					redirect_url='.$redirect_url.', sort_by='.$sort_by.', 
					cat_id='.$cat_id.', parent_forum_id='.$parent_forum_id.', published='.$published.' 
					WHERE id='.$forum_id);
		$database->setQuery($sql);
		$database->Query($sql);
		// Now let's deal with the permissions
		if (isset($_POST['read_forum_old'])) {
			$sql = ('SELECT g_id, g_read_board, g_post_replies, g_post_topics, g_post_polls, g_rss_enabled
							FROM #__forum_groups 
							WHERE g_id!='.YARBB_ADMIN);
			$database->setQuery($sql);
			$cur_group_result = $database->loadAssocList();

			foreach ($cur_group_result as $cur_group) {
				$read_forum_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['read_forum_new'][$cur_group['g_id']]) ? $_POST['read_forum_new'][$cur_group['g_id']] : '0' : $_POST['read_forum_old'][$cur_group['g_id']];
				$post_replies_new = isset($_POST['post_replies_new'][$cur_group['g_id']]) ? $_POST['post_replies_new'][$cur_group['g_id']] : '0';
				$post_topics_new = isset($_POST['post_topics_new'][$cur_group['g_id']]) ? $_POST['post_topics_new'][$cur_group['g_id']] : '0';
				$post_polls_new = isset($_POST['post_polls_new'][$cur_group['g_id']]) ? $_POST['post_polls_new'][$cur_group['g_id']] : '0';
				$rss_enabled_new = ($cur_group['g_read_board'] == '1') ? isset($_POST['rss_enabled_new'][$cur_group['g_id']]) ? $_POST['rss_enabled_new'][$cur_group['g_id']] : '0' : $_POST['rss_enabled_old'][$cur_group['g_id']];
				// Check if the new settings differ from the old
				if ($read_forum_new != $_POST['read_forum_old'][$cur_group['g_id']] || $post_replies_new != $_POST['post_replies_old'][$cur_group['g_id']] || $post_topics_new != $_POST['post_topics_old'][$cur_group['g_id']] || $post_polls_new != $_POST['post_polls_old'][$cur_group['g_id']] || $rss_enabled_new != $_POST['rss_enabled_old'][$cur_group['g_id']] ) {
					// If the new settings are identical to the default settings for this group, delete it's row in forum_perms
					if ($read_forum_new == '1' && $post_replies_new == $cur_group['g_post_replies'] && $post_topics_new == $cur_group['g_post_topics'] && $post_polls_new == $cur_group['g_post_polls'] && $rss_enabled_new == $cur_group['g_rss_enabled']) {
						$sql = ('DELETE FROM #__forum_forum_perms
										WHERE group_id='.$cur_group['g_id'].' 
										AND forum_id='.$forum_id);
						$database->setQuery($sql);
						$database->Query($sql);
					}
					else {
						// Run an UPDATE and see if it affected a row, if not, INSERT
						$sql = ('UPDATE #__forum_forum_perms SET read_forum='.$read_forum_new.', post_replies='.$post_replies_new.', post_topics='.$post_topics_new.', post_polls='.$post_polls_new.', rss_enabled='.$rss_enabled_new.' WHERE group_id='.$cur_group['g_id'].' AND forum_id='.$forum_id);
						$database->setQuery($sql);
						$database->Query($sql);

						if (!$database->getAffectedRows())
							$sql = ('INSERT INTO #__forum_forum_perms (group_id, forum_id, read_forum, post_replies, post_topics, post_polls, rss_enabled) VALUES('.$cur_group['g_id'].', '.$forum_id.', '.$read_forum_new.', '.$post_replies_new.', '.$post_topics_new.', '.$post_polls_new.', '.$rss_enabled_new.')');
						$database->setQuery($sql);
						$database->Query($sql);
					}
				}
			}
		}
		// Regenerate the quickjump cache
		require_once $yarbb_admin_path.'/include/cache.php';
		generate_quickjump_cache();
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _E_ITEM_SAVED);
	}
	else if (isset($_POST['revert_perms'])) {

		$sql = ('DELETE FROM #__forum_forum_perms WHERE forum_id='.$forum_id);
		$database->setQuery($sql);
		$database->Query($sql);
		// Regenerate the quickjump cache
		require_once $yarbb_admin_path.'/include/cache.php';
		generate_quickjump_cache();
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums&amp;edit_forum='.$forum_id, _Y_FORUMDEFUPD);
	}
	// Fetch forum info
	$sql = ('SELECT id, forum_name, forum_desc, forum_key, forum_mdesc, redirect_url, num_topics, sort_by, cat_id, parent_forum_id, published FROM #__forum_forums WHERE id='.$forum_id);
	$database->setQuery($sql);
	$cur_forum_result = $database->loadResult();

	if (!$cur_forum_result)
		mosRedirect( 'index2.php?option=com_forum&amp;task=forums', _Y_404);
	$cur_forum_result = $database->loadAssocList();
	foreach ($cur_forum_result as $cur_forum);
	$parent_forums = Array();

	$sql = ('SELECT DISTINCT parent_forum_id FROM #__forum_forums WHERE parent_forum_id != 0');
	$database->setQuery($sql);
	while($r = $database->loadResult())
		$parent_forums[] = $r[0];
	?>
<table class="adminheading">
	<tr>
		<th class="menus"> <span><?php echo _Y_FORUMED; ?></span> </th>
	</tr>
</table>
<form id="adminForm" name="adminForm" method="post" action="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;edit_forum='.$forum_id; ?>">
	<input type="hidden" name="task" value="forums" />
	<input type="hidden" name="" value="save" tabindex="6" />
	<p>
		<input type="submit" name="save" value="<?php echo _CMN_SAVE; ?>" tabindex="6" />
		&nbsp;
		<input type="submit" name="revert_perms" value="<?php echo _DEFAULT; ?>" />
	</p>
	<table class="adminform">
		<tr>
			<th colspan="4"> <?php echo _Y_FORUMEDDET; ?></th>
		</tr>
		<tr><td  width="15%"><?php echo _Y_CMN_PUBLISHED; ?><td>
					<?php echo _YES; ?><input name="published" type="radio" value="1" <?php if ($cur_forum['published'] == '1') echo ' checked' ?> />&nbsp;
					<?php echo _NO; ?><input name="published" type="radio" value="0" <?php if ($cur_forum['published'] == '0') echo ' checked' ?> />

			</td></tr>
		<tr>
			<td><?php echo _NAME; ?></td>
			<td><input type="text" name="forum_name" size="35" maxlength="80" value="<?php echo yarbb_htmlspecialchars($cur_forum['forum_name']) ?>" tabindex="1" /></td>
		</tr>
		<tr>
			<td valign="top"><?php echo _Y_DESC; ?>:</td>
			<td><?php editorArea( 'editor1',  yarbb_htmlspecialchars($cur_forum['forum_desc']), 'forum_desc', '600', '230', '80', '10' ) ; ?></td>
		</tr>
		<tr>
			<td><?php echo _Y_FORUMMETAD; ?></td>
			<td><textarea  name="forum_mdesc" rows="3" cols="50" tabindex="3"><?php echo yarbb_htmlspecialchars($cur_forum['forum_mdesc']) ?></textarea>
				&nbsp;<?php echo mosToolTip(_Y_FORUMMETAD_D); ?></td>
		</tr>
		<tr>
			<td><?php echo _Y_E_M_KEY; ?></td>
			<td><textarea  name="forum_key" rows="3" cols="50" tabindex="3"><?php echo yarbb_htmlspecialchars($cur_forum['forum_key']) ?></textarea>
				&nbsp;<?php echo mosToolTip(_Y_FORUMKEYW); ?></td>
		</tr>
		<tr>
			<td><?php echo _E_CATEGORY; ?></td>
			<td><select name="cat_id" tabindex="4">
						<?php
						$sql = ('SELECT id, cat_name FROM #__forum_categories ORDER BY disp_position');
						$database->setQuery($sql);
						$cur_cat_result = $database->loadAssocList();
						foreach($cur_cat_result as $cur_cat) {
							$selected = ($cur_cat['id'] == $cur_forum['cat_id']) ? ' selected="selected"' : '';
							echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'"'.$selected.'>'.yarbb_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
						}
						?>
				</select>
			</td>
		</tr>
		<tr>
			<td><?php echo _Y_FORUMTOPS; ?></td>
			<td><select name="sort_by" tabindex="5">
					<option value="0"<?php if ($cur_forum['sort_by'] == '0') echo ' selected="selected"' ?>><?php echo _Y_FORUMSORT1; ?></option>
					<option value="1"<?php if ($cur_forum['sort_by'] == '1') echo ' selected="selected"' ?>><?php echo _Y_FORUMSORT2; ?></option>
				</select>
			</td>
		</tr>
		<tr>
			<td><?php echo _Y_FORUMURL; ?></td>
			<td><?php echo ($cur_forum['num_topics']) ? 'Only available in empty forums' : '<input type="text" name="redirect_url" size="45" maxlength="100" value="'.yarbb_htmlspecialchars($cur_forum['redirect_url']).'" tabindex="5" />'; ?></td>
		</tr>
		<tr>
			<td><?php echo _Y_FORUMPAR; ?></td>
			<td><select name="parent_forum">
					<option value="0"><?php echo _Y_FORUMNOPAR; ?></option>
						<?php
						if(!in_array($cur_forum['id'],$parent_forums)) {
							$sql = ('SELECT id, forum_name, parent_forum_id FROM #__forum_forums ORDER BY disp_position');
							$database->setQuery($sql);
							$forum_list_result = $database->loadAssocList();
							foreach($forum_list_result as $forum_list) {
								$selected = ($forum_list['id'] == $cur_forum['parent_forum_id']) ? ' selected="selected"' : '';
								if(!$forum_list['parent_forum_id'] && $forum_list['id'] != $cur_forum['id'])
									echo "\t\t\t\t\t\t\t\t\t\t\t".'<option value="'.$forum_list['id'].'"'.$selected.'>'.yarbb_htmlspecialchars($forum_list['forum_name']).'</option>'."\n";
							}
						}
						?>
				</select>
				&nbsp;<?php echo mosToolTip(_Y_FORUMPAR_D); ?> </td>
		</tr>
	</table>
	<p style="border: 1px solid #CCCCCC;margin: 5px;padding: 5px; background:#D9E2FF; width:97%;"><?php echo _Y_FORUMPERMD; ?></p>
	<table class="adminlist">
		<tr>
			<th colspan="6"> <?php echo _ACCESS_RIGHTS; ?></th>
		</tr>
		<tr>
			<td><b><?php echo _Y_O_GROUP; ?></b></td>
			<td><b><?php echo _Y_FORUMRE; ?></b></td>
			<td><b><?php echo _Y_FORUMREP; ?></b></td>
			<td><b><?php echo _Y_FORUMNEWP; ?></b></td>
			<td><b><?php echo _Y_FORUMREPO; ?></b></td>
			<td><b><?php echo _Y_FORUMRSS; ?></b></td>
		</tr>
			<?php
			$sql = ('SELECT g.g_id, g.g_title, g.g_read_board, g.g_post_replies, g.g_post_topics, fp.read_forum, fp.post_replies, fp.post_topics, fp.rss_enabled
				FROM #__forum_groups AS g 
				LEFT JOIN #__forum_forum_perms AS fp 
				ON (g.g_id=fp.group_id AND fp.forum_id='.$forum_id.') 
				WHERE g.g_id!='.YARBB_ADMIN.' 
				ORDER BY g.g_id');
			$database->setQuery($sql);
			$cur_perm_result = $database->loadAssocList();

			foreach ($cur_perm_result as $cur_perm) {
				$read_forum = ($cur_perm['read_forum'] != '0') ? true : false;
				$post_replies = (($cur_perm['g_post_replies'] == '0' && $cur_perm['post_replies'] == '1') || ($cur_perm['g_post_replies'] == '1' && $cur_perm['post_replies'] != '0')) ? true : false;
				$post_topics = (($cur_perm['g_post_topics'] == '0' && $cur_perm['post_topics'] == '1') || ($cur_perm['g_post_topics'] == '1' && $cur_perm['post_topics'] != '0')) ? true : false;
				$post_polls = (($cur_perm['g_post_polls'] == '0' && $cur_perm['post_polls'] == '1') || ($cur_perm['g_post_polls'] == '1' && $cur_perm['post_polls'] != '0')) ? true : false;
				$rss_enabled = ($cur_perm['rss_enabled'] != '0') ? true : false;
				// Determine if the current sittings differ from the default or not
				$read_forum_def = ($cur_perm['read_forum'] == '0') ? false : true;
				$post_replies_def = (($post_replies && $cur_perm['g_post_replies'] == '0') || (!$post_replies && ($cur_perm['g_post_replies'] == '' || $cur_perm['g_post_replies'] == '1'))) ? false : true;
				$post_topics_def = (($post_topics && $cur_perm['g_post_topics'] == '0') || (!$post_topics && ($cur_perm['g_post_topics'] == '' || $cur_perm['g_post_topics'] == '1'))) ? false : true;
				$post_polls_def = (($post_polls && $cur_perm['g_post_polls'] == '0') || (!$post_polls && ($cur_perm['g_post_polls'] == '' || $cur_perm['g_post_polls'] == '1'))) ? false : true;
				$rss_enabled_def = ($cur_perm['rss_enabled'] == '0') ? false : true;
				?>
		<tr>
			<td><b><?php echo yarbb_htmlspecialchars($cur_perm['g_title']) ?></b></td>
			<td<?php if (!$read_forum_def) echo ' class="nodefault"'; ?>><input type="hidden" name="read_forum_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($read_forum) ? '1' : '0'; ?>" />
				<input type="checkbox" name="read_forum_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($read_forum) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_read_board'] == '0') ? ' disabled="disabled"' : ''; ?> />
			</td>
			<td<?php if (!$post_replies_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>><input type="hidden" name="post_replies_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_replies) ? '1' : '0'; ?>" />
				<input type="checkbox" name="post_replies_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_replies) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
			</td>
			<td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>><input type="hidden" name="post_topics_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_topics) ? '1' : '0'; ?>" />
				<input type="checkbox" name="post_topics_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_topics) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
			</td>
			<td<?php if (!$post_topics_def && $cur_forum['redirect_url'] == '') echo ' class="nodefault"'; ?>><input type="hidden" name="post_polls_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($post_polls) ? '1' : '0'; ?>" />
				<input type="checkbox" name="post_polls_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($post_polls) ? ' checked="checked"' : ''; ?><?php echo ($cur_forum['redirect_url'] != '') ? ' disabled="disabled"' : ''; ?> />
			</td>
			<td<?php if (!$rss_enabled_def) echo ' class="nodefault"'; ?>><input type="hidden" name="rss_enabled_old[<?php echo $cur_perm['g_id'] ?>]" value="<?php echo ($rss_enabled) ? '1' : '0'; ?>" />
				<input type="checkbox" name="rss_enabled_new[<?php echo $cur_perm['g_id'] ?>]" value="1"<?php echo ($rss_enabled) ? ' checked="checked"' : ''; ?><?php echo ($cur_perm['g_rss_enabled'] == '0') ? ' disabled="disabled"' : ''; ?> />
			</td>
		</tr>
				<?php
			}
			?>
	</table>
</form>
	<?php

}
else {


	?>
<table class="adminheading">
	<tr>
		<th class="menus"> <span><?php echo _Y_FORUMS; ?></span> </th>
	</tr>
</table>
<form method="post" action="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;action=adddel'; ?>">
	<table class="adminform">
		<tr>
			<th colspan="5"> <?php echo _Y_FORUMNEWADD; ?></th>
		</tr>
		<tr>
			<td width="10%"><input type="submit" name="add_forum" value=" <?php echo _E_ADD; ?> " tabindex="2" /></td>
			<td><select name="add_to_cat" tabindex="1">
						<?php
						$sql = ('SELECT id, cat_name FROM #__forum_categories ORDER BY disp_position');
						$database->setQuery($sql);
						$cur_cat_result = $database->loadAssocList();
						foreach ($cur_cat_result as $cur_cat)
							echo "\t\t\t\t\t\t\t\t\t".'<option value="'.$cur_cat['id'].'">'.yarbb_htmlspecialchars($cur_cat['cat_name']).'</option>'."\n";
						?>
				</select>
				<span><?php echo mosToolTip(_Y_FORUMNEWADD_D); ?></span> </td>
		</tr>
	</table>
</form>
<table class="adminheading">
	<tr>
		<th class="menus"> <span><?php echo _Y_FORUMEDITOR; ?></span> </th>
	</tr>
</table>
<form id="edforum" method="post" action="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;action=edit'; ?>">
		<?php
		$tabindex_count = 4;
// Display all the categories and forums
		$sql = ('SELECT c.id AS cid, c.cat_name, f.id AS fid, f.forum_name, f.disp_position, f.forum_desc, f.published
			FROM #__forum_categories AS c 
			INNER JOIN #__forum_forums AS f ON c.id=f.cat_id 
			ORDER BY c.disp_position, c.id, f.disp_position');
		$database->setQuery($sql);
		$cur_forum_result = $database->loadAssocList();
		$cur_category = 0;
		foreach ($cur_forum_result as $cur_forum) {
			if ($cur_forum['cid'] != $cur_category)	// A new category since last iteration?
			{
				if ($cur_category != 0)
					echo "\t\t\t\t\t\t\t".''."\n\t\t\t\t\t\t".''."\n\t\t\t\t\t".''."\n\t\t\t\t".''."\n";
				?>
	<table class="adminlist">
		<tr>
			<td width="100%" colspan="6" ><b><?php echo _E_CATEGORY; ?>: &nbsp;<?php echo yarbb_htmlspecialchars($cur_forum['cat_name']) ?></b></td>
		</tr>
		<tr>
			<th width="10%">ID</th>
			<th width="20%"><?php echo _WEBLINK_NAME; ?></th>
			<th width="20%"><?php echo _Y_DESC; ?></th>
			<th><?php echo _Y_CMN_PUBLISHED; ?></th>
			<th width="15%"><?php echo _MODULE_POSITION; ?>&nbsp;
				<input type="submit" name="update_positions" value="<?php echo _UPDATE; ?>" tabindex="3" /></th>
			<th><?php echo _ACTION; ?></th>
		</tr>
					<?php
					$cur_category = $cur_forum['cid'];
				}
				?>
		<tr class="row0">
			<td align="center"><?php echo $cur_forum['fid'] ?></td>
			<td align="center" ><a href="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;edit_forum='.$cur_forum['fid']; ?>"><?php echo yarbb_htmlspecialchars($cur_forum['forum_name']) ?></a></td>
			<td align="left" ><?php echo $cur_forum['forum_desc']; ?></td>
			<td align="center">
						<?php
						$cur_file_icons_path = JPATH_SITE.'/'.JADMIN_BASE.'/templates/'.JTEMPLATE.'/images/ico';
						if ($cur_forum['published'] == '1') {
							// опубликовано
							$img = 'publish_g.png';
						}else {
							// Не опубликовано
							$img = 'publish_x.png';
						}
						?>
				<img class="img-mini-state" src="<?php echo $cur_file_icons_path;?>/<?php echo $img;?>" id="img-pub-<?php echo $row->id;?>" alt="<?php echo _PUBLISHING?>" /></td>
			<td align="center"><?php echo _MODULE_POSITION; ?>&nbsp;&nbsp;
				<input type="text" name="position[<?php echo $cur_forum['fid'] ?>]" size="2" maxlength="3" value="<?php echo $cur_forum['disp_position'] ?>" tabindex="<?php echo $tabindex_count ?>" /></td>
			<td align="center"><a href="<?php echo 'index2.php?option=com_forum&amp;task=forums&amp;del_forum='.$cur_forum['fid']; ?>"><?php echo _E_REMOVE; ?></a></td>
		</tr>
				<?php
				$tabindex_count += 2;
			}
			?>
	</table>
</form>
	<?php
}
